public class Joesphu {
    public static void main(String[] args) {
    CircleSingleLinkedList circleSingleLinkedList=new CircleSingleLinkedList();
    circleSingleLinkedList.add(10);
    circleSingleLinkedList.show();
    circleSingleLinkedList.del(1,2,10);
    }
}

class CircleSingleLinkedList{
    private Boy first=new Boy(-1);
    public void add(int no){
        if (no<1){
            System.out.println("输入有误");
            return;
        }
        Boy cur=new Boy();
        for (int i = 0; i < no+1; i++) {
            Boy boy=new Boy(i);
            if (i==1){//形成单向环形列表
                first=boy;
                boy.setNext(first);
                cur=first;
            }else {
                cur.setNext(boy);
                boy.setNext(first);
                cur=boy;
            }
        }
    }
    public void show(){
        if (first==null){
            System.out.println("链表为空");
            return;
        }
        Boy cur=new Boy();
        cur=first;
        while (true){
            System.out.println(cur);
            if (cur.getNext()==first){
                break;
            }
            cur=cur.next;
        }
    }
    public void del(int strNo,int countNo,int nums){
      if (first==null||strNo<1||strNo>nums){
          return;
      }
      Boy helper=first;
      while (true){
          if (helper.next==first){
              break;
          }
          helper=helper.next;
      }
        for (int i = 0; i < strNo-1; i++) {
            helper=helper.next;
            first=first.next;
        }
        while (true){
            if (helper==first){
                break;
            }
        for (int i = 0; i < countNo-1; i++) {
            helper = helper.next;
            first = first.next;
        }
            System.out.println(first.getNo());
            first=first.next;
            helper.setNext(first);
        }
        System.out.println(first.getNo());
    }

}
class Boy{
    public int no;
    public Boy next;

    public Boy(int no) {
        this.no=no;
    }

    public Boy() {
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public Boy getNext() {
        return next;
    }

    public void setNext(Boy next) {
        this.next = next;
    }

    @Override
    public String toString() {
        return "Boy{" +
                "no=" + no +
                '}';
    }
}